home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
adatimer.zip
/
TIMEL6.ADA
< prev
next >
Wrap
Text File
|
1990-06-07
|
2KB
|
78 lines
-- Listing 6. Slow timer demo program.
with POLLED_TIMER;
with DIM_FLOAT, ASCII_UTILITIES;
-- from Ada in Action by Do-While Jones.
with TEXT_IO;
procedure Slow_Polled_Timer_Demo is
type Seconds is new DIM_FLOAT.Units;
USED, LEFT : Seconds;
package TIMER is new POLLED_TIMER(Seconds);
procedure Put(TIME : Seconds) is
begin
TEXT_IO.Put(ASCII_UTILITIES.Fixed_Image
(Dimensionless(TIME)));
end Put;
begin
TEXT_IO.Put_Line("Slow Polled Timer Demo");
-- Show single mode
TIMER.Set(+2.0,TIMER.SINGLE);
TEXT_IO.Put_Line("Starting 2 second timer.");
TIMER.Start;
while not TIMER.Has_Expired loop null; end loop;
TEXT_IO.Put_Line("Timer has expired.");
-- Show reset and read-on-the-fly
TEXT_IO.Put_Line("Reading the timer on the fly.");
TIMER.Restart;
Delay(0.5);
USED := TIMER.Time_Used;
LEFT := TIMER.Time_Left;
Put(USED); TEXT_IO.Put_Line(" seconds used.");
Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
Delay(1.0);
USED := TIMER.Time_Used;
LEFT := TIMER.Time_Left;
Put(USED); TEXT_IO.Put_Line(" seconds used.");
Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
-- Show Stop and read while stopped.
TEXT_IO.Put_Line("Reading the timer when stopped.");
TEXT_IO.Put_Line("2 second timer started.");
TIMER.Restart;
Delay(0.5);
TIMER.Stop;
TEXT_IO.Put_Line("Stopped after 1/2 second.");
USED := TIMER.Time_Used;
LEFT := TIMER.Time_Left;
Put(USED); TEXT_IO.Put_Line(" seconds used.");
Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
Delay(1.0);
TEXT_IO.Put_Line("1 second later.");
USED := TIMER.Time_Used;
LEFT := TIMER.Time_Left;
Put(USED); TEXT_IO.Put_Line(" seconds used.");
Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
TEXT_IO.Put_Line("Let it run another 0.2 seconds.");
TIMER.Start;
Delay(0.2);
USED := TIMER.Time_Used;
LEFT := TIMER.Time_Left;
Put(USED); TEXT_IO.Put_Line(" seconds used.");
Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
-- Show repeat mode
TIMER.Set(+1.0,TIMER.REPEATED);
TEXT_IO.Put_Line
("Watching 1 second timer for 5 seconds.");
TIMER.Start;
for i in 1..5 loop
while not TIMER.Has_Expired loop null; end loop;
TEXT_IO.Put_Line(" Tick");
end loop;
TIMER.Stop;
TEXT_IO.New_Line;
TEXT_IO.Put_Line("Done.");
end Slow_Polled_Timer_Demo;